import { Model, DataTypes } from 'sequelize'
import { sequelize } from "../config/index.js"
import User from './User.js'
import Post from './Post.js'

// 定义一个 Comment 类 继承 Model
class Comment extends Model {}

// 通过 init 方法定义表的字段等信息
Comment.init(
  {
    content: {
      type: DataTypes.TEXT,
      allowNull: false,
    },
    createdAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
    },
  },
  { sequelize, modelName: 'Comment' }
);

// 关联评论和用户、文章
Comment.belongsTo(User, { foreignKey: 'userID' })
Comment.belongsTo(Post, { foreignKey: 'postID' })

export default Comment;